package com.aaa.advice;


import com.aaa.pointCut.MypointCut;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.junit.jupiter.api.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
//多个增强类通过Order来判定执行顺序值越小越先执行越大越后执行目标方法执行结束后会先执行值大的在由值小的收尾
@Order(10)
public class Demo01Aop {



    @Around("com.aaa.pointCut.MypointCut.a()")
//    ProceedingJoinPoint继承了JoinPoint 在JoinPoint的基础上暴露出 proceed()
    public Object executeTime(ProceedingJoinPoint pjp) throws Throwable {
        //获取方法中的参数
        Object[] args = pjp.getArgs();
        long start = System.currentTimeMillis();
        System.out.println(pjp.getSignature()+"方法开始执行了");
        //调用目标方法
        Object res = pjp.proceed(args);
        System.out.println(pjp.getSignature()+"方法执行结束了");
        long end = System.currentTimeMillis();
        System.out.println(pjp.getSignature() + "方法耗时：" + (end - start) + "毫秒");

        return res;
    }
}
